//
//  NavgationController.m
//  Budejie
//
//  Created by 远成物流 on 2017/5/15.
//  Copyright © 2017年 陈梦佳. All rights reserved.
//

#import "NavgationController.h"
#import "UIBarButtonItem+Item.h"

@interface NavgationController ()<UIGestureRecognizerDelegate>

@end

@implementation NavgationController

+(void)load{
    UINavigationBar *navBar = [UINavigationBar appearance];
    
    [navBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]}];
    
    [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(panGetureAction:)];
    
    [self.view addGestureRecognizer:pan];
    
    //非根控制器触发
    pan.delegate = self;
    
    //禁止之前手势
    self.interactivePopGestureRecognizer.enabled = NO;
}

#pragma mark - UIGestureDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    return self.childViewControllers.count > 1;
}

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count > 0) {
        //非根控制器
        viewController.hidesBottomBarWhenPushed = YES;
        //设置返回按钮
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithImage:[UIImage imageNamed:@"navigationButtonReturn"] highImage:[UIImage imageNamed:@"navigationButtonReturnClick"] target:self action:@selector(backAction:) title:@"返回"];
    }
    
    [super pushViewController:viewController animated:YES];
}

-(void)backAction:(id)sender{
    [self popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
